/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.sheet.environment;

import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import twaver.ElementAttribute;
import twaver.Node;
import twaver.table.TPropertySheet;
import twaver.table.TPropertySheetPane;
import demo.DemoPane;

public class EnvironmentDemo extends DemoPane {
	
    private TPropertySheet sheet = new TPropertySheet();
    private Node node = new Node();

	public EnvironmentDemo(){
		TPropertySheetPane sheetPane = new TPropertySheetPane(sheet);
		sheetPane.setShowValueInDescription(true);
		sheetPane.getDescriptionPane().setVisible(true);
		sheetPane.getCategoryButton().doClick();		
		this.sheet.setElement(node);
    	this.add(sheetPane, BorderLayout.CENTER);
		
		List attributes = new ArrayList();
        Iterator it = System.getProperties().keySet().iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            node.putUserProperty(key, System.getProperty(key));
            attributes.add(this.createAttribute(key));
        }		
        sheet.registerElementClassAttributes(Node.class, attributes);
        
        sheet.getColumnModel().getColumn(0).setHeaderValue("JAVA ENVIRONMENT PROPERTY KEY");
        sheet.getColumnModel().getColumn(1).setHeaderValue("DEFAULT VALUE");
	}
	
	private ElementAttribute createAttribute(String key){
    	ElementAttribute attribute = new ElementAttribute();
    	attribute.setUserPropertyKey(key);
    	attribute.setDisplayName(key);
    	attribute.setEditable(false);
    	return attribute;
	}	
}